package com.bestcem.xm.member.controller;

import com.bestcem.xm.common.core.uitls.IdUtil;
import com.bestcem.xm.component.security.annotation.AuthIgnore;
import com.bestcem.xm.member.service.SendMemberService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ming.xue <ming.xue@idiaoyan.com>
 * @desc 推送联系人
 * @date 2021-07-19
 */
@Slf4j
@RestController
@RequestMapping("/member")
public class SendMemberController {

    /**
     * 推送联系人服务
     */
    @Autowired
    private SendMemberService sendMemberService;

    /**
     * 推送联系人
     *
     * @param orgId
     * @return
     */
    @AuthIgnore
    @GetMapping("/send_member")
    public String sendMembers(@RequestParam(name = "org_id", required = false) String orgId) {
        if (StringUtils.isBlank(orgId)) {
            return sendMemberService.publishMemberSlices();
        } else {
            String transactionId = IdUtil.uuid();
            sendMemberService.publishOrgMemberSlices(orgId, transactionId);
            return transactionId;
        }
    }

}
